/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package maze.paint;

import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
//import java.awt.Graphics2D;

/**
 *
 * @author loki
 */
public class SelectionMenu extends StringPrinter {
    public enum Direction {
        UP,DOWN
    };
    
    public String title;
    private Color highlight, textColor;
    private int menu_pos;
    
    public SelectionMenu(String[] text, String title, int fontSize, int x, int y) {
        super(text, fontSize, x, y);
        
        this.title = title;
        this.highlight = Color.RED;
        this.textColor = Color.black;
    }
    
    @Override
    public void paint(Graphics g, int maxX, int maxY) {
        FontMetrics fontMetric = g.getFontMetrics(font);
        
        int middleY = middleY(maxY);
        
        
        this.paintBox(g, maxX, maxY);
        g.setFont(font);
        
        //Print text until the highlighted text, then print highlighted, then print the rest.
        g.setColor(textColor);
        g.drawString(title, x + middleX(fontMetric, maxX, title), fontSize*2);
        
        for(int y = 0; y < menu_pos; y++) {
            g.drawString(text[y], x + middleX(fontMetric, maxX, y), this.y + middleY + (y + 1)*fontSize);
        }
        
        g.setColor(highlight);
        g.drawString(text[menu_pos], x + middleX(fontMetric, maxX, menu_pos), this.y + middleY + (menu_pos + 1)*fontSize);
        
        g.setColor(textColor);
        for(int y = menu_pos + 1; y < text.length; y++) {
            g.drawString(text[y], x + middleX(fontMetric, maxX, y), this.y + middleY + (y + 1)*fontSize);
        }
        
    }
    
    public void move(Direction direction) {
        switch(direction) {
            case UP:
                if(menu_pos == 0) {
                    menu_pos = text.length - 1;
                } else {
                    menu_pos--;
                }
                break;
            case DOWN:
                if(menu_pos == text.length - 1) {
                    menu_pos = 0;
                } else {
                    menu_pos++;
                }
                break;
        }
    }
    
    /**
     * Retrieve the highlighted position
     */
    public int getHighlighted() {
        return this.menu_pos;
    }
}
